using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using FederatedScaleOutDatabases.Interfaces;

namespace FederatedScaleOutDatabases.Strategies
{
    public class FederationStrategy<T>
    {
        private Dictionary<Type, Expression> _federationInfo = null;

        /// <summary>
        /// A Strategy implementation to resolve a federated database for database operations
        /// </summary>
        public IFederationResolutionStrategy<T> FederationResolutionStrategy { get; set; }

        /// <summary>
        /// A strategy implementation to define the database(s) access strategy e.g. sequential, parallel, etc
        /// </summary>
        public IFederatedDatabaseAccessStrategy FederatedDatabaseAccessStrategy { get; set; }

        //TODO: Delegate to merge results back

        /// <summary>
        /// Fluent-style Method that helps to put simple Lambda expression based strategies for accessing certain federated database(s) for database operations.
        /// Use <see>
        ///       <cref>FederationStrategy.FederationResolutionStrategy</cref>
        ///     </see>  for complex strategies
        /// </summary>
        /// <typeparam name="T">Entity Type to use</typeparam>
        /// <param name="propertyToFederateOn">Expression wrapping a lambda expression defined on type T that returns a string signifying the Federated Database instance</param>
        /// <returns>This instance of <see>
        ///                             <cref>FederationStrategy</cref>
        ///                           </see> for adding additional options</returns>
        public FederationStrategy<T> FederateOn(Expression<Func<T, string>> propertyToFederateOn)
        {
            if (_federationInfo == null)
                _federationInfo = new Dictionary<Type, Expression>();

            _federationInfo.Add(typeof(T), propertyToFederateOn);
            return this;
        }

        public Dictionary<Type, Expression> FederateOnInfo { get { return _federationInfo; } }

    }
}
